<?php
	defined( '_JEXEC' ) or die( 'Restricted access' );
	jimport('joomla.application.component.view');
	
	class HizkimizkiViewDefault extends JView
	{
		var $_option = null;
		
		function display($tpl = null)
		{
			
			$model = &$this->getModel();
			
			$this->assignRef('languages', $model->getLanguages());
			$this->assignRef('option', JRequest::getCmd('option'));
			
			$this->addJS();
			
			parent::display($tpl);
		}

		function translations($tpl = null){
			$model = &$this->getModel();
			$reflang = JRequest::getString('langOriTrans',null);
			$this->assignRef('reflang', $reflang);
			$this->assignRef('refwords', $model->getLangWords($reflang));
			$this->assignRef('languages', $model->getLanguages());
			$this->assignRef('option', JRequest::getCmd('option'));
			
			$this->addAdminCSS();
			$this->addJS();

			$user =& JFactory::getUser();
			$show = false;
			
			if($user->id != 0){
				$show = true;
			}
			
			$this->assignRef('show',$show);

			parent::display($tpl);
		}

		function editTranslation($tpl = null){
			$model = &$this->getModel();

			$code = JRequest::getString('pcode', null);
			$lang = null;
			$words = null;
			$type = null;
			if($code == null){
				$code = JRequest::getString('code', null);
			}
			else{
				$lang = $model->getPLang($code);
				$words = $model->getPLangWords($code);
				$type = "prop";
			}
			if($code == null){
				print('code: '.$code);
				$link = 'index.php?option=com_hizkimizki&task=adminHizkimizki';
				JFactory::getApplication()->redirect($link, $msg='', $msgType='message');
			}
			if ($code !=null && $lang == null) {
				$lang = $model->getLang($code);
				$words = $model->getLangWords($code);
				$type = "accepted";
			}

			$refLang = JRequest::getString('refLang','eus');
			$this->assignRef('refLang', $refLang);
			$this->assignRef('refwords', $model->getLangWords($refLang));
			$this->assignRef('lang', $lang);
			$this->assignRef('words', $words);
			$this->assignRef('code', $code);
			$this->assignRef('type', $type);
			$this->assignRef('languages', $model->getLanguages());
			$this->assignRef('option', JRequest::getCmd('option'));

			$this->addAdminCSS();
			$this->addJS();

			parent::display($tpl);
		}

		function adminHizkimizki($tpl = null){
			$model = &$this->getModel();

			$this->assignRef('proposals', $model->getProposedLangs());
			$this->assignRef('langs', $model->getAllLanguages());
			$this->assignRef('option', JRequest::getCmd('option'));
			
			$this->addAdminCSS();
			$this->addAdminJS();
			
			parent::display($tpl);
		}
		
		function addJS(){

			$option=JRequest::getCmd('option');
			
			$document = &JFactory::getDocument();
			$document->addScript( 'components/'.$option.'/js/jquery-1.9.1.min.js' );
			$document->addScript( 'components/'.$option.'/js/hizkimizkiForm.js' );
			?>
			<script>
				<?php
				echo "\n var ERROR_MSG='".JText::_('ERROR_MSG')."';";
				?>
			</script>
			<?php
		}

		function addAdminJS(){
			$this->addJS();
			$option=JRequest::getCmd('option');			
			$document = &JFactory::getDocument();
			$document->addScript( 'components/'.$option.'/js/jquery.dataTables.min.js' );
			$document->addScript( 'components/'.$option.'/js/hizkimizkiAdmin.js' );
			$document->addScript( 'components/'.$option.'/js/jquery-ui-1.10.0.custom.min.js' );

			?>
			<script>
				<?php
				echo "\n var ERROR_MSG='".JText::_('ERROR_MSG')."';";
				?>
			</script>
			<?php
		}

		function addCSS(){
			$option = JRequest::getCmd('option');

			$document = &JFactory::getDocument();
			$document->addStyleSheet('components/'.$option.'/css/hizki.css');
		}

		function addAdminCSS(){
		
			$option = JRequest::getCmd('option');

			$document = &JFactory::getDocument();
			$document->addStyleSheet('components/'.$option.'/css/jquery-ui-1.10.0.custom.min.css');
			$document->addStyleSheet('components/'.$option.'/css/jquery.dataTables.css');
			$this->addCSS();
		}
		
	}
?>